# -*- coding: utf-8 -*-
'''
模块：生意通-周报-流量分析
输入：cookie,hotel_id,hotel_name
输出：
lastWeekStr # 周报日期
myHotel_totalListExposure # 我的酒店-列表页曝光
myHotel_listTransforDetailRate=myHotel['listTransforDetailRate'] # 我的酒店-曝光转化率
myHotel_totalDetailExposure=myHotel['totalDetailExposure'] # 我的酒店-详情页访问量
myHotel_detailTransforOrderFillRate=myHotel['detailTransforOrderFillRate'] # 我的酒店-下单转化率
myHotel_orderFillingNum=myHotel['orderFillingNum'] # 我的酒店-订单填写
myHotel_orderFillTransforOrderSubmitRate=myHotel['orderFillTransforOrderSubmitRate'] # 我的酒店-成交转化率
myHotel_orderSubmitNum=myHotel['orderSubmitNum'] # 我的酒店-订单提交

competeHotelAvg_totalListExposure = competeHotelAvg['totalListExposure'] # 竟争圈-列表页曝光
competeHotelAvg_listTransforDetailRate = competeHotelAvg['listTransforDetailRate'] # 竟争圈-曝光转化率
competeHotelAvg_totalDetailExposure = competeHotelAvg['totalDetailExposure'] # 竟争圈-详情页访问量
competeHotelAvg_detailTransforOrderFillRate = competeHotelAvg['detailTransforOrderFillRate'] # 竟争圈-下单转化率
competeHotelAvg_orderFillingNum = competeHotelAvg['orderFillingNum'] # 竟争圈-订单填写
competeHotelAvg_orderFillTransforOrderSubmitRate = competeHotelAvg['orderFillTransforOrderSubmitRate'] # 竟争圈-成交转化率
competeHotelAvg_orderSubmitNum = competeHotelAvg['orderSubmitNum'] # 竟争圈-订单提交

topCompeteHotel_totalListExposure = topCompeteHotel['totalListExposure'] # 同城标杆-列表页曝光
topCompeteHotel_listTransforDetailRate = topCompeteHotel['listTransforDetailRate'] # 同城标杆-曝光转化率
topCompeteHotel_totalDetailExposure = topCompeteHotel['totalDetailExposure'] # 同城标杆-详情页访问量
topCompeteHotel_detailTransforOrderFillRate = topCompeteHotel['detailTransforOrderFillRate'] # 同城标杆-下单转化率
topCompeteHotel_orderFillingNum = topCompeteHotel['orderFillingNum'] # 同城标杆-订单填写
topCompeteHotel_orderFillTransforOrderSubmitRate = topCompeteHotel['orderFillTransforOrderSubmitRate'] # 同城标杆-成交转化率
topCompeteHotel_orderSubmitNum = topCompeteHotel['orderSubmitNum'] # 同城标杆-订单提交
'''
import requests
import json
from fcs import url_request

def main(cookies,hotel_id,hotel_name):
    item={}
    url="http://syt.ctrip.com/api/dataCenter/report/getLastWeekReport?hostType=Ebooking"
    header={
        'Content-Type':'application/json'
    }

    while True:
        try:
            con=url_request.post_url_requests(url=url,cookies=cookies,headers=header,data={})
            json_data = json.loads(con)['data']
            break
        except:
            continue

    # con=requests.post(url=url,cookies=cookies,headers=header).text
    lastWeekStr=json_data['lastWeekStr']
    item.update(lastWeekStr=lastWeekStr)

    url = "http://syt.ctrip.com/api/dataCenter/report/getTrafficReport?hostType=Ebooking"
    # con = requests.post(url=url, cookies=cookies, headers=header).text

    while True:
        try:
            con=url_request.post_url_requests(url=url,cookies=cookies,headers=header,data={})
            json_data = json.loads(con)['data']
            break
        except:
            continue

    myHotel=json_data['myHotel']
    myHotel_totalListExposure=myHotel['totalListExposure']
    myHotel_listTransforDetailRate=myHotel['listTransforDetailRate']
    myHotel_totalDetailExposure=myHotel['totalDetailExposure']
    myHotel_detailTransforOrderFillRate=myHotel['detailTransforOrderFillRate']
    myHotel_orderFillingNum=myHotel['orderFillingNum']
    myHotel_orderFillTransforOrderSubmitRate=myHotel['orderFillTransforOrderSubmitRate']
    myHotel_orderSubmitNum=myHotel['orderSubmitNum']
    item.update(myHotel_totalListExposure=myHotel_totalListExposure)
    item.update(myHotel_listTransforDetailRate=myHotel_listTransforDetailRate)
    item.update(myHotel_totalDetailExposure=myHotel_totalDetailExposure)
    item.update(myHotel_detailTransforOrderFillRate=myHotel_detailTransforOrderFillRate)
    item.update(myHotel_orderFillingNum=myHotel_orderFillingNum)
    item.update(myHotel_orderFillTransforOrderSubmitRate=myHotel_orderFillTransforOrderSubmitRate)
    item.update(myHotel_orderSubmitNum=myHotel_orderSubmitNum)

    competeHotelAvg=json_data['competeHotelAvg']
    competeHotelAvg_totalListExposure = competeHotelAvg['totalListExposure']
    competeHotelAvg_listTransforDetailRate = competeHotelAvg['listTransforDetailRate']
    competeHotelAvg_totalDetailExposure = competeHotelAvg['totalDetailExposure']
    competeHotelAvg_detailTransforOrderFillRate = competeHotelAvg['detailTransforOrderFillRate']
    competeHotelAvg_orderFillingNum = competeHotelAvg['orderFillingNum']
    competeHotelAvg_orderFillTransforOrderSubmitRate = competeHotelAvg['orderFillTransforOrderSubmitRate']
    competeHotelAvg_orderSubmitNum = competeHotelAvg['orderSubmitNum']
    item.update(competeHotelAvg_totalListExposure=competeHotelAvg_totalListExposure)
    item.update(competeHotelAvg_listTransforDetailRate=competeHotelAvg_listTransforDetailRate)
    item.update(competeHotelAvg_totalDetailExposure=competeHotelAvg_totalDetailExposure)
    item.update(competeHotelAvg_detailTransforOrderFillRate=competeHotelAvg_detailTransforOrderFillRate)
    item.update(competeHotelAvg_orderFillingNum=competeHotelAvg_orderFillingNum)
    item.update(competeHotelAvg_orderFillTransforOrderSubmitRate=competeHotelAvg_orderFillTransforOrderSubmitRate)
    item.update(competeHotelAvg_orderSubmitNum=competeHotelAvg_orderSubmitNum)

    topCompeteHotel=json_data['topCompeteHotel']
    topCompeteHotel_totalListExposure = topCompeteHotel['totalListExposure']
    topCompeteHotel_listTransforDetailRate = topCompeteHotel['listTransforDetailRate']
    topCompeteHotel_totalDetailExposure = topCompeteHotel['totalDetailExposure']
    topCompeteHotel_detailTransforOrderFillRate = topCompeteHotel['detailTransforOrderFillRate']
    topCompeteHotel_orderFillingNum = topCompeteHotel['orderFillingNum']
    topCompeteHotel_orderFillTransforOrderSubmitRate = topCompeteHotel['orderFillTransforOrderSubmitRate']
    topCompeteHotel_orderSubmitNum = topCompeteHotel['orderSubmitNum']
    item.update(topCompeteHotel_totalListExposure=topCompeteHotel_totalListExposure)
    item.update(topCompeteHotel_listTransforDetailRate=topCompeteHotel_listTransforDetailRate)
    item.update(topCompeteHotel_totalDetailExposure=topCompeteHotel_totalDetailExposure)
    item.update(topCompeteHotel_detailTransforOrderFillRate=topCompeteHotel_detailTransforOrderFillRate)
    item.update(topCompeteHotel_orderFillingNum=topCompeteHotel_orderFillingNum)
    item.update(topCompeteHotel_orderFillTransforOrderSubmitRate=topCompeteHotel_orderFillTransforOrderSubmitRate)
    item.update(topCompeteHotel_orderSubmitNum=topCompeteHotel_orderSubmitNum)

    return item
